home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / POINTERS.MOD < prev    next >
Text File  |  1989-01-18  |  860b  |  42 lines

  1.                                         (* Chapter 12 - Program 1 *)
  2. MODULE Pointers;
  3.  
  4. FROM InOut   IMPORT WriteString, WriteInt, WriteLn;
  5. FROM Storage IMPORT ALLOCATE, DEALLOCATE;
  6. FROM SYSTEM  IMPORT TSIZE;
  7.  
  8. TYPE Name = ARRAY[0..20] OF CHAR;
  9.  
  10. VAR  MyName : POINTER TO Name;    (* MyName points to a string *)
  11.      MyAge  : POINTER TO INTEGER; (* MyAge points to an INTEGER *)
  12.  
  13. BEGIN
  14.  
  15.    ALLOCATE(MyAge,TSIZE(INTEGER));
  16.    ALLOCATE(MyName,TSIZE(Name));
  17.  
  18.    MyAge^ := 27;
  19.    MyName^ := "John Q. Doe";
  20.  
  21.    WriteString("My name is ");
  22.    WriteString(MyName^);
  23.    WriteString(" and I am ");
  24.    WriteInt(MyAge^,2);
  25.    WriteString(" years old.");
  26.    WriteLn;
  27.  
  28.    DEALLOCATE(MyAge,TSIZE(INTEGER));
  29.    DEALLOCATE(MyName,TSIZE(Name));
  30.  
  31. END Pointers.
  32.  
  33.  
  34.  
  35.  
  36. (* Result of execution
  37.  
  38. My name is John Q Doe and I am 27 years old.
  39.  
  40. *)
  41.  
  42.